package conteroller

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"zc/api/global"
	"zc/api/terquest"
	pb "zc/rpc/api/video"
)

func VideoAdd(c *gin.Context) {
	var App terquest.VideoAdd
	if err := c.ShouldBindJSON(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	// 4. 调用接口
	response, err := global.VideoClient.VideoAdd(context.Background(), &pb.VideoAddReq{
		VideoTitle:   App.VideoTitle,
		VideoName:    App.VideoName,
		VideoInfo:    App.VideoInfo,
		VideoAddress: App.VideoAddress,
		VideoProfile: App.VideoProfile,
	})
	if err != nil {
		fmt.Printf("响应异常  %s\n\n", err)
	}
	fmt.Printf("响应结果： %v\n", response)
	c.JSON(http.StatusOK, gin.H{"code": "200", "msg": "添加成功"})

}
func VideoList(c *gin.Context) {
	var App terquest.VideoAdd
	if err := c.ShouldBindJSON(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	res, _ := global.VideoClient.VideoList(context.Background(), &pb.VideoListRequest{
		VideoTitle: App.VideoTitle,
		Page:       1,
		PageSize:   3,
	})
	fmt.Println(res)
	c.JSON(http.StatusOK, gin.H{"code": "200", "msg": "查询成功", "date": res})
}
